import logging
import time
from jaeger_client import Config
import random

def get_client():
    config = Config(
        config={ # usually read from some yaml config
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'logging': True,
        },
        service_name='your-app-name',
        validate=True,
    )
    tracer = config.initialize_tracer()
    return tracer


if __name__ == "__main__":
    log_level = logging.DEBUG
    logging.getLogger('').handlers = []
    logging.basicConfig(format='%(asctime)s %(message)s', level=log_level)
    tests = 'qwertyuiop'

    tracer = get_client()
    for ii in range(1000):

        with tracer.start_span('TestSpan') as span:
            span.log_kv({'event': 'test message', 'life': random.randint(10000, 99999), 'bug': 'not me'})
            span.log_kv({'test message': 'xxxxxxx', 'life333': random.randint(10000, 99999), 'bug': random.choices(tests)})

            with tracer.start_span('ChildSpan', child_of=span) as child_span:
                child_span.log_kv({'event': 'down below', 'sdfdsfsd': 'sdfsdfsdeeeeeeeeeeeee'})
                child_span.log_kv({'test message': 'xxxxxxx', 'life333': random.randint(10000, 99999), 'bug': random.choices(tests)})

            span.log_kv({'ddddddddd': 'zzzz',})

    time.sleep(0.1)
